using System;
using System.Collections.Generic;
using System.Linq;

namespace unTroublemaker.Conditions
{
    public class AnyCondition : SpecificationItemBase
    {
        public AnyCondition(IEnumerable<ISpecificationItem> items)
        {
            ChildItems = items.ToArray();
            if(ChildItems.Length == 0)
                throw new ArgumentException("Requires at least one child item", "items");
        }
        
        protected override bool RunTest()
        {
            foreach (var item in ChildItems)
                item.Run();

            return ChildItems.Any(i => i.Passed);
        }

        public override string DisplayName
        {
            get { return "Check that at least one item passes"; }
        }
    }
}